package edu.psu.collegerecommendationtool.coreservlets;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

import edu.psu.collegerecommendationtool.model.EducationInfo;
import edu.psu.collegerecommendationtool.model.UserBean;


@ManagedBean(name="modifyEducation")
public class ModifyEducationInfoBean {
@ManagedProperty(value="#{userBean}")
   private UserBean user;

   private float entered_GPA;
   private short entered_mathSAT;
   private short entered_creadSAT;
   private short entered_writeSAT;
   private byte entered_mathACT;
   private byte entered_readACT;
   private byte entered_englishACT;
   private byte entered_scienceACT;

   private EducationInfo educationInfo;


   public UserBean getUser() {
      return user;
   }
   public void setUser(UserBean user) {
      this.user = user;
   }

   public float getEntered_GPA() {
      return entered_GPA;
   }
   public void setEntered_GPA(float entered_GPA) {
      this.entered_GPA = entered_GPA;
   }

   public short getEntered_mathSAT() {
      return entered_mathSAT;
   }
   public void setEntered_mathSAT(short entered_mathSAT) {
      this.entered_mathSAT = entered_mathSAT;
   }

   public short getEntered_creadSAT() {
      return entered_creadSAT;
   }
   public void setEntered_creadSAT(short entered_creadSAT) {
      this.entered_creadSAT = entered_creadSAT;
   }

   public short getEntered_writeSAT() {
      return entered_writeSAT;
   }
   public void setEntered_writeSAT(short entered_writeSAT) {
      this.entered_writeSAT = entered_writeSAT;
   }

   public byte getEntered_mathACT() {
      return entered_mathACT;
   }
   public void setEntered_mathACT(byte entered_mathACT) {
      this.entered_mathACT = entered_mathACT;
   }

   public byte getEntered_readACT() {
      return entered_readACT;
   }
   public void setEntered_readACT(byte entered_readACT) {
      this.entered_readACT = entered_readACT;
   }

   public byte getEntered_englishACT() {
      return entered_englishACT;
   }
   public void setEntered_englishACT(byte entered_englishACT) {
      this.entered_englishACT = entered_englishACT;
   }

   public byte getEntered_scienceACT() {
      return entered_scienceACT;
   }
   public void setEntered_scienceACT(byte entered_scienceACT) {
      this.entered_scienceACT = entered_scienceACT;
   }

   public EducationInfo getEducationInfo() {
      return educationInfo;
   }
   public void setEducationInfo(EducationInfo educationInfo) {
      this.educationInfo = educationInfo;
   }

////////////////////////////////////////////////////////////////////////


public String saveEducationInfo() {
      boolean action = false;
      educationInfo = user.getEducationInfo();

      if ((entered_GPA != educationInfo.getGPA()) &&
          (0 != entered_GPA)) {
         educationInfo.setGPA(entered_GPA);
         action = true;
      }

      if ((entered_mathSAT != educationInfo.getMathSAT()) &&
          (0 != entered_mathSAT)) {
         educationInfo.setMathSAT(entered_mathSAT);
         action = true;
      }

      if ((entered_creadSAT != educationInfo.getCreadSAT()) &&
          (0 != entered_creadSAT)) {
         educationInfo.setCreadSAT(entered_creadSAT);
         action = true;
      }

      if ((entered_writeSAT != educationInfo.getWriteSAT()) &&
          (0 != entered_writeSAT)) {
         educationInfo.setWriteSAT(entered_writeSAT);
         action = true;
      }

      if ((entered_mathACT != educationInfo.getMathACT()) &&
          (0 != entered_mathACT)) {
         educationInfo.setMathACT(entered_mathACT);
         action = true;
      }

      if ((entered_readACT != educationInfo.getReadACT()) &&
          (0 != entered_readACT)) {
         educationInfo.setReadACT(entered_readACT);
         action = true;
      }

      if ((entered_englishACT != educationInfo.getEnglishACT()) &&
          (0 != entered_englishACT)) {
         educationInfo.setEnglishACT(entered_englishACT);
         action = true;
      }

      if ((entered_scienceACT != educationInfo.getScienceACT()) &&
          (0 != entered_scienceACT)) {
         educationInfo.setScienceACT(entered_scienceACT);
         action = true;
      }

      
      if(true == action) {
         user.setEducationInfo(educationInfo);
         user.saveEducationInfo();
      }

      return ("ModifyInfoPage");
   }

}